#include <cstdio>
#include <algorithm>

using namespace std;

typedef long long ll;
const int maxn=100000;

int main() {
    freopen("delete.in", "r", stdin);
    freopen("delete.out", "w", stdout);

    static int a[maxn+1], mp=1, deg[maxn+1];
    int n;
    ll ans=0;
    scanf("%d", &n);
    for (int i=1; i<=n; i++) {
        scanf("%d", a+i);
        ans+=a[i];
        if (a[i]>a[mp]) mp = i;
    }
    ans-=a[mp];

    for (int i=1; i<n; i++) {
        int u, v;
        scanf("%d %d", &u, &v);
        ans+=max(a[u], a[v]);
    }
    printf("%lld\n", ans);

    fclose(stdin);
    fclose(stdout);
    return 0;
}
